package com.fuda.trade.model
import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions
import kotlin.random.Random

class TradeOrderDataUnitTest {
    @Test
    fun serialize_isCorrect() {
        val buyAuto = TradeOrderData.Buy(
            securityCode = "SH.STK.600519",
            securityName = "贵州茅台",
            pricingType = TradeOrderData.PricingType.Limit,
            price = 160+ Random(160).nextDouble(),
            volume = 100,
            desc = "Publish1@TradeOrderDataUnitTest.kt",
            isAuto = true
        )

        val payload = TradeOrderData.serialize(buyAuto)

        val tradeOrderData = TradeOrderData.deserialize(payload)

        when (tradeOrderData){
            is TradeOrderData.Buy -> {
                Assertions.assertEquals(tradeOrderData.securityCode, "SH.STK.600519")
            }
            is TradeOrderData.Sell -> {
                Assertions.assertEquals(tradeOrderData.securityCode, "SH.STK.600519")
            }

        }

        println("\n\nserialized Order= $payload\n")

        Assertions.assertEquals(buyAuto, tradeOrderData)
    }
}